package com.wanxi.controller.front;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.model.NewsType;
import com.wanxi.service.NewsService;
import com.wanxi.vo.NewsVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("news")
@CrossOrigin(origins = "http://localhost:8081")
@RequestMapping("/news")
public class NewsController {

    @Autowired
    NewsService newsService;

    @GetMapping("/find")
    public String findEnableNews(NewsVO newsVO,
                                 @Param("newsTypeID") String newsTypeID){
        newsVO.setNewsType(NewsType.builder().id(newsTypeID).build());
        ResultDTO news = newsService.findNews(newsVO);
        return JSONObject.toJSONString(news);
    }

    @PostMapping("/findById")
    public String findById(NewsVO newsVO){
        ResultDTO newsById = newsService.findNewsById(newsVO);
        return JSONObject.toJSONString(newsById);
    }
}
